/**
 * @param {Array} data 成绩数据
 * @param {Object} query 查询条件
 * @return {Array} 返回符合条件的数组
 */
function queryScoreList(data, query) {
  let resultArr = [];
  // TODO:待补充代码
  if (query?.perfectScore == true)
    resultArr = data.filter((item) =>
      /\[\{"1":100\},\{"2":100\},\{"3":100\},\{"4":100\},\{"5":150\},\{"6":150\}\]/.test(
        JSON.stringify(item)
      )
    );
  if (query?.score == "0")
    resultArr = data.filter((item) =>
      /\[\{"1":0\},\{"2":0\},\{"3":0\},\{"4":0\},\{"5":0\},\{"6":0\}\]/.test(
        JSON.stringify(item)
      )
    );
  if (query?.score == "缺考")
    resultArr = data.filter((item) =>
      /\[\{"1":"缺考"\},\{"2":"缺考"\},\{"3":"缺考"\},\{"4":"缺考"\},\{"5":"缺考"\},\{"6":"缺考"\}\]/.test(
        JSON.stringify(item)
      )
    );
  if (query?.failedFew == true) {
    const reg =
      /\[\{"1":(\w+)\},\{"2":(\w+)\},\{"3":(\w+)\},\{"4":(\w+)\},\{"5":(\w+)\},\{"6":(\w+)\}\]/;
    resultArr = data.filter((item) => {
      let matches = reg.exec(JSON.stringify(item));
      if (matches) {
        if (
          matches[1] < 60 ||
          matches[2] < 60 ||
          matches[3] < 60 ||
          matches[4] < 60 ||
          matches[5] < 90 ||
          matches[6] < 90
        )
          return true;
      }
    });
  }
  if (query.students != undefined) {
    const students = query.students.split(",");
    resultArr = data.filter((item) => {
      if (students.some((reg) => JSON.stringify(item).includes(reg)))
        return true;
    });
  }
  return resultArr;
}

try {
  module.exports = queryScoreList;
} catch (e) {}
